package Xue;

import java.util.ArrayList;
import java.util.Scanner;

public class ManageStudent {
    //储存学生
    StudentBean[] sBeans=new StudentBean[50];
    ArrayList<StudentBean> saArrayList=new ArrayList<StudentBean>();
    Scanner scanner=new Scanner(System.in);
    
	public ManageStudent() {
		sBeans[0]=new StudentBean(1902, "zjl", "男",1001);
		sBeans[1]=new StudentBean(1902, "dbb", "女",1002);
		sBeans[2]=new StudentBean(1902, "hb", "男",1003);
		sBeans[3]=new StudentBean(1902, "lws", "男",1004);
		sBeans[4]=new StudentBean(1902, "yth", "男",1005);
	}
	//查询
	public void showStudent() {
		System.out.println("学号\t姓名\t性别\t班级");
		for (StudentBean studentBean : sBeans) {
			if (studentBean!=null) {
				System.out.println(studentBean.getCode()+"\t"+
			studentBean.getNameString()+"\t"+studentBean.getGenderString()+"\t"+
						studentBean.getClassid());
			}
			
		}
	}
	//删
	public void deleteStudent() {
		System.out.println("请输入要删除的学生下标");
		int index=scanner.nextInt();
		sBeans[index]=null;
		System.out.println("删除成功");
	}
	//增
	public void addStudent() {
	for (int i = 0; i < sBeans.length; i++) {
		if (sBeans[sBeans.length-1]!=null) {
			System.out.println("添加失败，这个班级学生人数已满");
		}
		if (sBeans[i]!=null) {
		    System.out.println("姓名");
		    String nameString=scanner.next();
		    System.out.println("性别");
		    String genString=scanner.next();
		    //先把最后一位学生学号拿到
		    int code=0;
		    for (int j = sBeans.length-1; j >=0 ; j--) {
		    	if (sBeans[j]!=null) {
					code=sBeans[j].getCode();
					break;
				}
			}
		    StudentBean studentBean=new StudentBean(code+1, nameString, genString,1902);
		    sBeans[i]=studentBean;
		    System.out.println("添加成功");
		    break;
		    }
	    }
    }
	//改
	public void setStudent() {
		System.out.println("请输入要改的下标");
		int index=scanner.nextInt();
	    StudentBean studentBean=sBeans[index];
	    if (studentBean!=null) {
	    	System.out.println("是否修改学生姓名(y/n)");
	    	if (scanner.next().equals("y")) {
				System.out.println("请输入学生姓名");
				studentBean.setNameString(scanner.next());
			}
	    	sBeans[index]=studentBean;
	    	 System.out.println("修改成功");
		}else {
			System.out.println("修改失败");
		}
    }
}
